﻿/**

 * Copyright (c) 2015-2016, FastDev 刘强 (fastdev@163.com).

 *

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *      http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using RazorEngine;
using RazorEngine.Templating;
using RazorEngine.Configuration;
using RazorEngine.Compilation;
using System.Reflection;
using System.IO;
using System.Linq.Expressions;
using RazorEngine.Text; // For extension methods.
using OF.SmartMVC.Core.Compile;
using OF.SmartMVC.Core.Compile.Template;
using OF.SmartMVC.Core;
using OF.SmartMVC.TestView;

namespace OF.SmartMVC.Test
{
    public class Program
    {
        private static Type binderType = typeof(Microsoft.CSharp.RuntimeBinder.Binder);
        
        static void Main(string[] args)
        {
            TestCreateCode();
            Console.WriteLine("生成成功，请将 Gen 目录下生成的dll拷贝到应用程序目录，再点击回车查看调用结果！");
            Console.ReadLine();
            TestRunCode();
        }

        private static void TestCreateCode()
        {
            CompiledViewBuilder cb = new CompiledViewBuilder(typeof(OF.SmartMVC.TestView.App), "OF.SmartMVC.View");
            cb.Add("Resource.Index", typeof(User));
            cb.Add("Resource.Content", typeof(string));
            cb.Generate();
        }

        private static void TestRunCode()
        {
            EngineHelper.LoadAssembly(App.AssemblyName);
            string result = EngineHelper.RunView(new RunViewRequest
            {
                assemblyName = App.AssemblyName,
                viewName = "Resource.Index",
                model = new User { Name = "测试用户" }
            });
            Console.WriteLine(result);
            Console.ReadLine();
        }
    }


    public class Address
    {
        public string AddressName;
    }

    public class User
    {
        public string Name;
    }
}